import java.sql.*
import groovy.sql.Sql

class Example {
    static void main(String[] args){
        // creating a connection to the database
        def sql = Sql.newInstance('jdbc:mysql://localhost:3306/demo?useSSL=false','root','1234','com.mysql.jdbc.Driver')

        sql.connection.autoCommit = false
        def sqlstr = "DELETE FROM EMPLOYEE WHERE AGE>20";
        try{
            sql.execute(sqlstr);
            sql.commit();
            println("Successfully committed")
        }catch(Exception ex){
            sql.rollback();
            println("Transaction rollback")
        }

        sql.close()
    }
}